<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div{
            position: fixed;
            bottom: 10px;
            left: 10px;
            height: 50px;
            background-color: aqua;
            
        }
    </style>
    <script src="socket.io/socket.io.js"></script>
</head>
<body>
    <ul>
        
    </ul>
    <div>
        <input type="text" name="" id="msg"><input type="button" name="" id="sendMsg" value="发送">
    </div>
    <script>
        var msg = document.getElementById("msg");
        var sendMsg = document.getElementById("sendMsg");
        var oul = document.getElementsByTagName("ul")[0];
         let socket = io();
        sendMsg.onclick=function()
        {
             socket.emit("chatMsg",msg.value);
             socket.on("severSend",(data)=>{
                 oul.innerHTML = `<li>${data}</li>`+ oul.innerHTML;
             })
        }
    </script>
</body>
</html>